#pragma once
#include <phone.h>

#include "Settings.h"
#include "ListData.h"

#include <vector>

#define FILETIME_ONE_DAY  864000000000  // 100-nanosecods blocks in one day
#define FILETIME_SIX_DAYS  5184000000000  // 100-nanosecods blocks in six days

class CallLogEntry
{
public:
  CallLogEntry();

  bool hasName() const
  { return (szName[0] != 0); }
  bool hasNumber() const
  { return (szNumber[0] != 0); }

  bool isRepeating(const CallLogEntry& b) const;

  TCHAR    szName[PRIMARY_TEXT_LENGTH];
  TCHAR    szNumber[PRIMARY_TEXT_LENGTH];
  CEOID    oId;
  ItemPropertyType numberType;
  CallType callType;
  FILETIME ftStart;
  FILETIME ftEnd;
  TCHAR    cPastTime;
  TCHAR    szPastTime[SECONDARY_TEXT_LENGTH];
  int      numRepeats;
  TCHAR    szRepeatingInfo[PRIMARY_TEXT_LENGTH*2];
};

class ListDataCallLog : public CListBase
{
  typedef std::vector<CallLogEntry*> CCallLogEntryList;

public:
  ListDataCallLog(HWND hWnd, CallType forType = ctAll);
  virtual ~ListDataCallLog();

  virtual void Clear();

  void Reload(CallType forType, bool fullReload = false);
  bool OutlookContactChanged(CEOID oId);

protected:
  bool PopulateCListByDB();
  void PopulateCListByPhone();

  void Populate();

  bool AddListEntry(CallLogEntry* pEntry);
  void ClearList(CCallLogEntryList& list);

  ItemPropertyType ParseNumberType(const TCHAR* type);

  CEOID FindOid(const CallLogEntry& cEntry);

protected:
  CallType          callType;
  CCallLogEntryList listMissed;
  CCallLogEntryList listIncoming;
  CCallLogEntryList listOutgoing;

private:
  TCHAR _getPastTime(FILETIME ftTime, TCHAR * pszSecondary, int strLength);
  void _printTime(TCHAR * str, int strLength, FILETIME ft);
};
